package org.xtframe.util;

import java.util.ResourceBundle;

import org.xtframe.bean.SystemConfig;

/**
 * 
 * @author SunYong
 *
 * 系统配置工具类
 */
public class SystemConfigUtil {
	
	// 系统配置文件名称，省略了后缀".properties"
	public static final String CONFIG_FILE_NAME = "xtframe";
	
	// systemConfig缓存Key
	public static final String SYSTEM_CONFIG_CACHE_KEY = "systemConfig";
	
	public static SystemConfig getSystemConfig(){
		SystemConfig systemConfig = (SystemConfig) OsCacheUtil.getFromCache(SYSTEM_CONFIG_CACHE_KEY);
		if (systemConfig != null) {
			return systemConfig;
		}
		ResourceBundle cache = null;
		try {
			cache = ResourceBundle.getBundle(CONFIG_FILE_NAME);
		} catch (RuntimeException e) {
			e.printStackTrace();
		}
		
		systemConfig = new SystemConfig();
		systemConfig.setSqlType(Integer.valueOf(cache.getString("sqlType")));
		systemConfig.setNextvalRegSequence1Sql(cache.getString("nextvalRegSequence1Sql"));
		systemConfig.setNextvalRegSequence2Sql(cache.getString("nextvalRegSequence2Sql"));
		systemConfig.setServiceInitSqlSql(cache.getString("serviceInitSqlSql"));
		systemConfig.setServiceInitMenuSql(cache.getString("serviceInitMenuSql"));
		systemConfig.setServiceInitLogicSql(cache.getString("serviceInitLogicSql"));
		systemConfig.setServiceInitResSql(cache.getString("serviceInitResSql"));
		systemConfig.setServiceInitDictionarySql(cache.getString("serviceInitDictionarySql"));
		systemConfig.setServiceInitRoleSql(cache.getString("serviceInitRoleSql"));
		systemConfig.setServiceInitSystemDataSql(cache.getString("serviceInitSystemDataSql"));
		systemConfig.setRoleInitMenuSql(cache.getString("roleInitMenuSql"));
		systemConfig.setRoleInitSqlSql(cache.getString("roleInitSqlSql"));
		systemConfig.setRoleInitLogicSql(cache.getString("roleInitLogicSql"));
		systemConfig.setRoleInitResSql(cache.getString("roleInitResSql"));
		systemConfig.setUserInitInfoSql(cache.getString("userInitInfoSql"));
		systemConfig.setUserInitOrganSql(cache.getString("userInitOrganSql"));
		systemConfig.setUserInitJobSql(cache.getString("userInitJobSql"));
		systemConfig.setUserInitRoleSql(cache.getString("userInitRoleSql"));
		systemConfig.setUserInitOptroleSql(cache.getString("userInitOptroleSql"));
		systemConfig.setUserOrganDataSql(cache.getString("userOrganDataSql"));
		systemConfig.setServiceInitDataBaseSql(cache.getString("serviceInitDataBaseSql"));
		systemConfig.setDataBaseInitSqlSql(cache.getString("dataBaseInitSqlSql"));
		systemConfig.setTaskPageSql(cache.getString("taskPageSql"));
		systemConfig.setStartProcessSql(cache.getString("startProcessSql"));
		systemConfig.setTaskRecordSql(cache.getString("taskRecordSql"));
		systemConfig.setDeleteTaskRecordSql(cache.getString("deleteTaskRecordSql"));
		systemConfig.setStopProcessSql(cache.getString("stopProcessSql"));
		
		systemConfig.setVerifyIsChinese(cache.getString("verifyIsChinese"));
		systemConfig.setVerifyIs2Byte(cache.getString("verifyIs2Byte"));
		systemConfig.setVerifyIsBlank(cache.getString("verifyIsBlank"));
		systemConfig.setVerifyIsHtml(cache.getString("verifyIsHtml"));
		systemConfig.setVerifyIsTrim(cache.getString("verifyIsTrim"));
		systemConfig.setVerifyIsEmail(cache.getString("verifyIsEmail"));
		systemConfig.setVerifyIsUrl(cache.getString("verifyIsUrl"));
		systemConfig.setVerifyIsName(cache.getString("verifyIsName"));
		systemConfig.setVerifyIsChinaTel(cache.getString("verifyIsChinaTel"));
		systemConfig.setVerifyIsQQ(cache.getString("verifyIsQQ"));
		systemConfig.setVerifyIsPostal(cache.getString("verifyIsPostal"));
		systemConfig.setVerifyIsIdentity(cache.getString("verifyIsIdentity"));
		systemConfig.setVerifyIsIp(cache.getString("verifyIsIp"));
		systemConfig.setVerifyIsLetter(cache.getString("verifyIsLetter"));
		systemConfig.setVerifyIsBLetter(cache.getString("verifyIsBLetter"));
		systemConfig.setVerifyIsSLetter(cache.getString("verifyIsSLetter"));
		systemConfig.setVerifyIsNumLetter(cache.getString("verifyIsNumLetter"));
		systemConfig.setVerifyIsNum_Letter(cache.getString("verifyIsNum_Letter"));
		systemConfig.setVerifyIsZInt(cache.getString("verifyIsZInt"));
		systemConfig.setVerifyIsFInt(cache.getString("verifyIsFInt"));
		systemConfig.setVerifyIsInt(cache.getString("verifyIsInt"));
		systemConfig.setVerifyIsZInt0(cache.getString("verifyIsZInt0"));
		systemConfig.setVerifyIsFInt0(cache.getString("verifyIsFInt0"));
		systemConfig.setVerifyIsZDouble(cache.getString("verifyIsZDouble"));
		systemConfig.setVerifyIsFDouble(cache.getString("verifyIsFDouble"));
		systemConfig.setVerifyIsDouble(cache.getString("verifyIsDouble"));
		systemConfig.setVerifyIsZDouble0(cache.getString("verifyIsZDouble0"));
		systemConfig.setVerifyIsFDouble0(cache.getString("verifyIsFDouble0"));
		
		systemConfig.setLoginPageUri(cache.getString("loginPageUri"));
		systemConfig.setUploadLimit(Integer.valueOf(cache.getString("uploadLimit")));
		systemConfig.setAllowedUploadImageExtension(cache.getString("allowedUploadImageExtension"));
		systemConfig.setAllowedUploadMediaExtension(cache.getString("allowedUploadMediaExtension"));
		systemConfig.setAllowedUploadFileExtension(cache.getString("allowedUploadFileExtension"));
		systemConfig.setAllowedUploadDeployExtension(cache.getString("allowedUploadDeployExtension"));
		
		OsCacheUtil.putInCache(SYSTEM_CONFIG_CACHE_KEY, systemConfig);
		return systemConfig;
	}
}
